<?php
class AlbumController extends Zend_Controller_Action
{
	
	    
    public function listeralbumAction() {
    	
    	
    	$photos=new Table_Photos();
    	$vip=new Table_Vips();
    	$pageAlbum=$this->_getParam('pageAlbum');
    	$photoSel=$this->_getParam('numPhoto');
    	$vipNum=$this->_getParam('vipNum');
    	
    	if (empty($pageAlbum))
    	{
    		$pageAlbum=1;
    	}
    	
    	//au lieu que le serveur php traite tout on laisse le sgbd faire le travail
    	$allPhotos=$photos->getAllPhotosLimited($pageAlbum*9-9,9);
    	$cmbphotos=$photos->getNbPhotos();
    	$i=1;
    	foreach($allPhotos as $result)
		{
			$mesPagesphotos[$i]=$result;
			$i++;
		}
		$pages=$cmbphotos->total/9;
		$pages=$pages+0.5;
		$pages=round($pages);
		
		$i=1;
		$j=1;
		$k=0;
		
		/*methode obsolete*/
		
		//on organise les pages
		/*for($i;$i<=count($temp)-1;$i++)
		{
			$k=$k+1;
			$mesPagesphotos[$j][$k]=$temp[$i];
			
			if($i%9==0 && $i!=0)
			{
				$k=0;
				$j=$j+1;
			}
		}*/
		
		if(!empty($photoSel) && !empty($vipNum))
		{
			$photoVip=$photos->getPhotoByID($photoSel,$vipNum);
			$monvip['NOM']=$vip->getNomVIP($vipNum);
			$monvip['PRENOM']=$vip->getPrenomVIP($vipNum);
			$photoAff['VIP']=$monvip['PRENOM']->VIP_PRENOM.' '.$monvip['NOM']->VIP_NOM;
			$photoAff['ADRESSE']=$photoVip->PHOTO_ADRESSE;
			$photoAff['COMMENTAIRE']=$photoVip->PHOTO_COMMENTAIRE;
			if (empty($photoAff['COMMENTAIRE']))
			{
				$photoAff['COMMENTAIRE']="Pas de commentaire";
			}
			
			$this->view->listeralbum=array(
				 'pages' => $pages,
				 'pageAlbum'=>$pageAlbum,
				 'photos' => $mesPagesphotos,			
				 'photoAff' => $photoAff
			);
			
		}
		else
		{
		
			$this->view->listeralbum=array(					
					 'pageAlbum'=>$pageAlbum,
					 'pages' => $pages,
					 'photos' => $mesPagesphotos
			);
		}
    } 


}
?>